// hyb_yl/nextjiuzhen/nextjiuzhen.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    startdate: null,
    enddate: null,
    date: "",
    times: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    console.log(options)
    if (options.ds_id) {
      var ds_id = options.ds_id
      //查询我的提醒内容
      app.util.request({
        'url': 'entry/wxapp/Selecttx',
        data: {
          ds_id: ds_id
        },
        success: function(res) {
          var timearr = res.data.data.timearr
          var detal = res.data.data
          that.setData({
            detal: detal,
            timearr: timearr
          })
        }
      })
      that.setData({
        ds_id: ds_id
      })
    }

    this.setdates();
  },
  setdates() {
    var that = this;
    var dates = new Date();
    var year = dates.getFullYear();
    var month = dates.getMonth() + 1 > 9 ? dates.getMonth() + 1 : "0" + (dates.getMonth() + 1);
    var day = dates.getDate() > 9 ? dates.getDate() : "0" + dates.getDate();
    var hors = dates.getHours() > 9 ? dates.getHours() : "0" + dates.getHours();
    var fen = dates.getMinutes() > 9 ? dates.getMinutes() : "0" + dates.getMinutes();
    that.setData({
      date: year + "-" + month + "-" + day,
      startdate: year + "-" + month + "-" + day,
      enddate: year + 10 + "-" + month + "-" + day,
      times: hors + ":" + fen
    })
  },
  datesel(e) {
    this.setData({
      date: e.detail.value
    })
  },
  timesel(e) {
    this.setData({
      times: e.detail.value
    })
  },
  remind(e) {
    var that = this;
    var dates = that.data.date;
    var times = that.data.times;
    var val = e.detail.value;
    var content = val.content
    var xiangmu = val.xiangmu
    var xctime = dates + ' ' + times
    console.log(e)
    var formid = e.detail.formId
    if (val.xiangmu == "") {
      wx.showToast({
        title: '项目不能为空',
        image: "/hyb_yl/images/err.png"
      })
    } else {
      //添加定时
      app.util.request({
        'url': 'entry/wxapp/Savestime',
        data: {
          timearr: xctime,
          content: content,
          openid: wx.getStorageSync('openid'),
          xiangmu: xiangmu,
          formid: formid
        },
        success: function(res) {
          console.log(res)
          var pages = getCurrentPages();
          var prevPage = pages[pages.length - 2];
          prevPage.setData({
            xctime: xctime
          })
          wx.navigateBack({
            delta: 1
          })
        }
      })

    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  shouye: function() {
    wx.reLaunch({
      url: '/hyb_yl/tabBar/index/index',
    })
  }
})